use clap::Parser;
use wtask_base::{error::WResult, export::{kill_channel, log_error}, logs::LogArgs, machine::runtime_init};
use wtask_file::MachineWebDAVServer;




#[derive(Debug, Parser, Clone)]
pub struct CMDSubWebDav {
    #[arg(default_value = "5005")]
    port: u32,

    #[command(flatten)]
    pub log_args: LogArgs,
}

impl CMDSubWebDav {
    pub fn run(self) -> WResult<()> {
        let runtime = runtime_init(4)?;
        let webdav = MachineWebDAVServer::new(self.port);
        runtime.block_on(async move {
            let (_t, kill_rx) = kill_channel(false);
            let v = webdav.listen(kill_rx).await;
            if let Err(e) = v {
                log_error!("MachineWebDav stop: {e}");
            }
        });
        runtime.shutdown_background();
        Ok(())
    }
}
